//
//  OrdinaryTeacherAccountVC.m
//  优学荟管理系统
//
//  Created by 星道 on 2017/9/30.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "OrdinaryTeacherAccountVC.h"
#import "OrdinaryTeacherAccountVM.h"
#import "OrdinaryTeacherAddVC.h"

@interface OrdinaryTeacherAccountVC ()
{
    
    IBOutlet UITableView *_TableView;
    IBOutlet UIActivityIndicatorView *_Activity;
}

@property (nonatomic, strong) OrdinaryTeacherAccountVM *ViewModel;
@end

@implementation OrdinaryTeacherAccountVC

#pragma makr - cycle life
- (void)viewDidLoad {

    [super viewDidLoad];

    self.title = @"机构老师";
    /** 表单的配置 */
    [self.ViewModel ConfigTableVIew:_TableView];
    /** 获取老师的信息并通过block回调 */
    [self.ViewModel RefreshDataWithActivity:_Activity Complete:^(NSArray<OrdinaryTeacherAccountModel *> *Arr) {
        if (Arr.count <= 0) return;
        // 停止并消失转圈
        /** 刷新图表 */
        [self.ViewModel ReloadData:_TableView Arr:Arr Animate:YES];
    }];

    // 添加账号
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"添加账号" style:(UIBarButtonItemStylePlain) target:self action:@selector(AddTeacher)];
}

/** 添加账号 */
- (void)AddTeacher {
    [self.navigationController pushViewController:[OrdinaryTeacherAddVC new] animated:YES];
}

#pragma mark - get
- (OrdinaryTeacherAccountVM *)ViewModel {

    if (!_ViewModel) {

        _ViewModel = [[OrdinaryTeacherAccountVM alloc] init];
        __weak typeof(self)WeakSelf = self;
        _ViewModel.Upload = ^(OrdinaryTeacherAccountModel *Model) {
            OrdinaryTeacherAddVC *VC = [[OrdinaryTeacherAddVC alloc] init];
            VC.ID = Model.uid;
            
           
            
            [WeakSelf.navigationController pushViewController:VC animated:YES];
        };
    }
    return _ViewModel;
}
@end
